/// @tags: DP DSU on Tree
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

namespace BlueQuantum {

constexpr int MAXN = 2e5 + 3;

int n;
int w[MAXN];
multiset<int> f[MAXN];
vector<int> G[MAXN];

inline void merge(int u, int v) {
  if (f[u].size() < f[v].size()) swap(f[u], f[v]);
  f[u].insert(f[v].begin(), f[v].end());
}

void dfs(int u) {
  for (auto v : G[u]) dfs(v), merge(u, v);
  f[u].insert(w[u]);
  auto it = f[u].lower_bound(w[u]);
  if (it != f[u].begin()) f[u].erase(--it);
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> w[i];
  for (int i = 2, fa; i <= n; ++i) {
    cin >> fa;
    G[fa].push_back(i);
  }
  dfs(1);
  cout << f[1].size();
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4577 [FJOI2018] 领导集团问题.in", "r", stdin);
  freopen("P4577 [FJOI2018] 领导集团问题.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
